﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Solution.EntityFrameworkCore.Migrations
{
    public partial class c1 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Departments",
                columns: table => new
                {
                    depId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    depName = table.Column<string>(nullable: true),
                    depRemark = table.Column<string>(nullable: true),
                    depIsDel = table.Column<bool>(nullable: false),
                    depAddTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Departments", x => x.depId);
                });

            migrationBuilder.CreateTable(
                name: "permissions",
                columns: table => new
                {
                    perId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    perParent = table.Column<int>(nullable: false),
                    perName = table.Column<string>(nullable: true),
                    perRemark = table.Column<string>(nullable: true),
                    perAreaName = table.Column<string>(nullable: true),
                    perControllerName = table.Column<string>(nullable: true),
                    perActionName = table.Column<string>(nullable: true),
                    perFormMethod = table.Column<short>(nullable: false),
                    perOperationType = table.Column<short>(nullable: false),
                    perJsMethodName = table.Column<string>(nullable: true),
                    perIco = table.Column<string>(nullable: true),
                    perIsLink = table.Column<bool>(nullable: false),
                    perOrder = table.Column<int>(nullable: false),
                    perIsShow = table.Column<bool>(nullable: false),
                    perIsDel = table.Column<bool>(nullable: false),
                    perAddTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_permissions", x => x.perId);
                });

            migrationBuilder.CreateTable(
                name: "roles",
                columns: table => new
                {
                    roleId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    roleDepId = table.Column<int>(nullable: true),
                    roleName = table.Column<string>(nullable: true),
                    roleIsDel = table.Column<bool>(nullable: false),
                    roleAddTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_roles", x => x.roleId);
                });

            migrationBuilder.CreateTable(
                name: "Employees",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    AddedTime = table.Column<DateTime>(nullable: false),
                    ModifiedTime = table.Column<DateTime>(nullable: false),
                    Enabled = table.Column<bool>(nullable: false),
                    empDepId = table.Column<int>(nullable: true),
                    empCnName = table.Column<string>(nullable: true),
                    empLoginName = table.Column<string>(nullable: true),
                    empLoginPwd = table.Column<string>(nullable: true),
                    empSex = table.Column<bool>(nullable: false),
                    empAge = table.Column<short>(nullable: false),
                    empCellPhone = table.Column<string>(nullable: true),
                    empPhone = table.Column<string>(nullable: true),
                    empAddress = table.Column<string>(nullable: true),
                    empIsDel = table.Column<bool>(nullable: false),
                    empAddTime = table.Column<DateTime>(nullable: false),
                    DepartmentdepId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Employees", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Employees_Departments_DepartmentdepId",
                        column: x => x.DepartmentdepId,
                        principalTable: "Departments",
                        principalColumn: "depId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "RolePerRelationships",
                columns: table => new
                {
                    rprId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    rprRoleId = table.Column<int>(nullable: false),
                    rprPerId = table.Column<int>(nullable: false),
                    PermissionperId = table.Column<int>(nullable: true),
                    roleId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RolePerRelationships", x => x.rprId);
                    table.ForeignKey(
                        name: "FK_RolePerRelationships_permissions_PermissionperId",
                        column: x => x.PermissionperId,
                        principalTable: "permissions",
                        principalColumn: "perId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_RolePerRelationships_roles_roleId",
                        column: x => x.roleId,
                        principalTable: "roles",
                        principalColumn: "roleId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "empRoleRelations",
                columns: table => new
                {
                    erId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    erUId = table.Column<int>(nullable: false),
                    erRId = table.Column<int>(nullable: false),
                    EmployeeId = table.Column<Guid>(nullable: true),
                    roleId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_empRoleRelations", x => x.erId);
                    table.ForeignKey(
                        name: "FK_empRoleRelations_Employees_EmployeeId",
                        column: x => x.EmployeeId,
                        principalTable: "Employees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_empRoleRelations_roles_roleId",
                        column: x => x.roleId,
                        principalTable: "roles",
                        principalColumn: "roleId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "vipPermssions",
                columns: table => new
                {
                    vpId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    vpUId = table.Column<int>(nullable: false),
                    vpPId = table.Column<int>(nullable: false),
                    EmployeeId = table.Column<Guid>(nullable: true),
                    PermissionperId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_vipPermssions", x => x.vpId);
                    table.ForeignKey(
                        name: "FK_vipPermssions_Employees_EmployeeId",
                        column: x => x.EmployeeId,
                        principalTable: "Employees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_vipPermssions_permissions_PermissionperId",
                        column: x => x.PermissionperId,
                        principalTable: "permissions",
                        principalColumn: "perId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Employees_DepartmentdepId",
                table: "Employees",
                column: "DepartmentdepId");

            migrationBuilder.CreateIndex(
                name: "IX_empRoleRelations_EmployeeId",
                table: "empRoleRelations",
                column: "EmployeeId");

            migrationBuilder.CreateIndex(
                name: "IX_empRoleRelations_roleId",
                table: "empRoleRelations",
                column: "roleId");

            migrationBuilder.CreateIndex(
                name: "IX_RolePerRelationships_PermissionperId",
                table: "RolePerRelationships",
                column: "PermissionperId");

            migrationBuilder.CreateIndex(
                name: "IX_RolePerRelationships_roleId",
                table: "RolePerRelationships",
                column: "roleId");

            migrationBuilder.CreateIndex(
                name: "IX_vipPermssions_EmployeeId",
                table: "vipPermssions",
                column: "EmployeeId");

            migrationBuilder.CreateIndex(
                name: "IX_vipPermssions_PermissionperId",
                table: "vipPermssions",
                column: "PermissionperId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "empRoleRelations");

            migrationBuilder.DropTable(
                name: "RolePerRelationships");

            migrationBuilder.DropTable(
                name: "vipPermssions");

            migrationBuilder.DropTable(
                name: "roles");

            migrationBuilder.DropTable(
                name: "Employees");

            migrationBuilder.DropTable(
                name: "permissions");

            migrationBuilder.DropTable(
                name: "Departments");
        }
    }
}
